package emap;

import java.awt.Image;
import javax.swing.ImageIcon;

import java.awt.Toolkit;
import java.awt.image.*;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

//Essentially just a tileset for objects. I should probably add some more info.

class ObjectGfxSheet {
	private String myFilename;
	private Image[] imageset;
	public final int htiles=4,vtiles=4;//lol
	private int imageanims;
	public ObjectGfxSheet(String filename) {
		myFilename = filename;
		String path = "objectset/" + myFilename + ".png";
		System.out.println(path);
		ImageIcon ico = new ImageIcon(this.getClass().getResource(path));
		Image bigImg = ico.getImage();
		imageanims = (ico.getIconHeight() / (48*vtiles));
		imageset = new Image[htiles*vtiles*imageanims];
		int count=0;
		for (int y = 0; y < vtiles*imageanims; y++)
		{
			for (int x = 0; x < htiles; x++)
			{
				imageset[count] = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bigImg.getSource(), new CropImageFilter(x*32, y*48, 32, 48)));
				count++;
			}
		}
	}
	//Primary set determines human/chicken/human2,etc.
	//Direction=down 0,left 1,right 2,up 3
	//Frame = which frame, 0-3
	public Image getObjectGfx(int primaryset,int direction,int frame)
	{
		if(primaryset<imageanims && primaryset>=0)
			return imageset[primaryset*16+direction*4+frame];
		return null;
	}
	public Image rawgetObjectGfx(int imgptr)
	{
		if(imgptr<imageanims*htiles*vtiles && imgptr>=0)
			return imageset[imgptr];
		return null;
	}
	public int getNumGfx()
	{
		return imageanims;
	}
}

//I feel that this should be stuck here. I don't know why. -Langston

class NullBufferedImageOp implements BufferedImageOp {
	public NullBufferedImageOp(){}
	public BufferedImage filter(BufferedImage src, BufferedImage dest){
		dest=src;
		return src;
	}
	public BufferedImage createCompatibleDestImage(BufferedImage src,ColorModel destCM){return null;}
	public RenderingHints getRenderingHints(){return null;}
	public Rectangle2D getBounds2D(BufferedImage src){return null;}
	public Point2D getPoint2D(Point2D srcPt,Point2D dstPt){dstPt=srcPt;return srcPt;};
	}
